package com.itany.corejava.code13_jdbc;

/**
 * @author MissChen
 * @date 2024年03月22日 10:50
 */
public class Emp {
    private Integer id;
    private String name;
    private Double salary;
    // private Integer deptId;

    // 对于主外键关系，在Java中一般使用对象来进行维护
    // 上面的deptId对应的是emp表中的dept_id字段，dept_id是emp表中的外键，dept_id是引用t_dept表中的id主键
    //在Java中，相当于将当前对象与Dept对象进行关联
    // 此时的属性可以直接使用对象属性来维护，而不需要使用外键字段
    private Dept dept;


    public Emp() {
    }

    // public Emp(String name, Double salary, Integer deptId) {
    //     this.name = name;
    //     this.salary = salary;
    //     this.deptId = deptId;
    // }
    //
    // public Emp(Integer id, String name, Double salary, Integer deptId) {
    //     this.id = id;
    //     this.name = name;
    //     this.salary = salary;
    //     this.deptId = deptId;
    // }

    public Emp(String name, Double salary, Dept dept) {
        this.name = name;
        this.salary = salary;
        this.dept = dept;
    }

    public Emp(Integer id, String name, Double salary, Dept dept) {
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.dept = dept;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getSalary() {
        return salary;
    }

    public void setSalary(Double salary) {
        this.salary = salary;
    }

    // public Integer getDeptId() {
    //     return deptId;
    // }
    //
    // public void setDeptId(Integer deptId) {
    //     this.deptId = deptId;
    // }


    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }

    @Override
    public String toString() {
        return "Emp{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", salary=" + salary +
                ", dept=" + dept +
                '}';
    }
}
